package com.sqsf.util;

import com.sqsf.javabean.User;
import mapper.UserMapper;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

public class UserMapperTest {
    SqlSession session;
    UserMapper mapper;

    @Before
    public void before() {
        SqlSessionFactory factory = MyBatisUtil.getSqlSessionFactory();
        session = factory.openSession(true);
        mapper = session.getMapper(UserMapper.class);

    }

    @After
    public void after() {
        //5、关闭资源
        session.close();
    }
    @Test
    public void selectAll(){
        for (User user : mapper.selectAll()) {
            System.out.println(user);
        }
    }
    @Test
    public void selectByUsernameAndPassword(){
        for (User user : mapper.selectByUsernameAndPassword("a1","a2")) {
            System.out.println(user);
        }
    }

    @Test
    public void selectByUsername(){
        for (User user : mapper.selectByUsername("a1")) {
            System.out.println(user);
        }
    }

    @Test
    public void deleteByUid(){
        mapper.deleteByUid(55);
    }

    @Test
    public void updatePasswordByUid(){
        mapper.updatePasswordByUid(55,"a");
    }
    @Test
    public void insertUser(){
        User u=new User("a1","a2","a3");
        mapper.insertUser(u);
    }

    @Test
    public void selectUser(){
        for (User user : mapper.selectUser()) {
            System.out.println(user);
        }
    }
    @Test
    public void selectUser1(){
        for (User user : mapper.selectUser1()) {
            System.out.println(user);
        }
    }
    @Test
    public void selectUser_Role(){
        for (User user : mapper.selectUser_Role()) {
            System.out.println(user);
        }
    }
    @Test
    public void deleteByArray(){
        int[] array={5,6,7,8,9};
        mapper.deleteByArray(array);
    }
}